<?
	// download
	// folders and subfolders shouldn't have spaces
	try {
		if(isset($_GET['file'])) {		
			require_once("engine/www/combustion.php");
			require_once ROOT . 'engine/ext/dropbox/dropbox.php';
			
			$dp = engine_get( 'json:social.dropbox.account' );
			$Dropbox = new Dropbox($dp->key, $dp->secret);
			$Dropbox->setOAuthToken($dp->token);	
			$Dropbox->setOAuthTokenSecret($dp->token_secret);
			$user = $Dropbox->accountInfo();
			$folder = $dp->subfolder;
		    $file = $_GET['file'];
		    
		    $fileGet = $folder . $_GET[ 'file' ];
		    $response = $Dropbox->filesGet( $fileGet );
		
		    header('Content-type: '. $response[ 'content_type' ]);
		    header('Content-Disposition: attachment; filename="'.$file.'"');
		    echo base64_decode($response[ 'data' ]);
		
		    exit;
		}
	} catch (Exception $e) {
		echo " <script language='JavaScript'>history.go(-1);</script>";  
		//echo 'Caught exception: ',  $e->getMessage(), "\n";
	}
	
?>